package top.kaoshanji.ch03;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 代码清单 ch03-07：一个数组示例(抽奖3)
 * author kaoshanji
 * ^_^
 * create time 2024/11/24 11:25
 */
public class LotteryDrawing {

    private static final Logger logger = LogManager.getLogger(LotteryDrawing.class);

    public static void main(String[] args) {
        logger.info("...代码清单 ch03-07：一个数组示例(抽奖3)...");

        Scanner in = new Scanner(System.in);

        // 假如抽取 6 个数字
        System.out.print("How many numbers do you need to draw? ");
        int k = in.nextInt();

        // 假如从 49 个数字中
        System.out.print("What is the highest number you can draw? ");
        int n = in.nextInt();


        int[] numbers = new int[n];
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = i + 1;
        }

        int[] result = new int[k];
        for (int i = 0; i < result.length; i++) {
            int r = (int) (Math.random() * n);

            result[i] = numbers[r];

            numbers[r] = numbers[n - 1];

            n--;
        }

        Arrays.sort(result);
        System.out.println("Bet the following combination. It'll make you rich!");
        for (int r : result) {
            System.out.println(r);
        }


    }

}
